package com.app.freshmenapp.service.impl;

import com.app.freshmenapp.dao.InformsDao;
import com.app.freshmenapp.entity.Informs;
import com.app.freshmenapp.service.InformsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Auther: Administrator
 * @Date: 2019.07.20 17:06
 * @Description: 通知服务层
 */

@Service
@SuppressWarnings("all")
public class InformsServiceImpl implements InformsService {

    @Autowired
    private InformsDao informsDao;

    @Override
    public boolean addInforms(Informs informs) {
        Informs informs1 = informsDao.saveAndFlush(informs);
        if(informs1!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteInforms(Integer id) {
        if(informsDao.existsById(id)){
            informsDao.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean updateInforms(Informs informs) {
        Informs informs1 = informsDao.saveAndFlush(informs);
        if(informs1!=null){
            return true;
        }
        return false;
    }

    @Override
    public Informs findById(Integer id) {
        if (informsDao.existsById(id)){
            Optional<Informs> optionalInforms=informsDao.findById(id);
            return optionalInforms.get();
        }
        return null;
    }

    @Override
    public List<Informs> findAllInforms() {
        return informsDao.findAll();
    }
}
